package com.hs.shirodemo2.exception;

import com.hs.shirodemo2.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//@ControllerAdvice将当前类标识为异常处理的组件
@ControllerAdvice
public class ExceptionController {

    //@ExceptionHandler用于设置所标识方法处理的异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e){
        return Result.error(e.getMessage());
    }

}